// pages/index/HomeNav/PsychologicalAQ/answer/answer.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    neirong:"",
    questionId:"",
    userId:""
  },
  fasong(){
    let that=this
    wx.request({
      method:"POST",
      url: 'http://localhost:8080/reply/add',
      data:{
        replyReplyText:that.data.neirong,
        questionId:that.data.questionId,
        userId:that.data.userId
      }
    })
  },
  onLoad(options){
    let that=this
    wx.getStorage({
      key: 'userInfo',
      success: (res) => {
          const userInfo = res.data;
          if (!userInfo) {
              wx.showToast({
                title: '还没有登录',
              })
              wx.redirectTo({
                  url: '/pages/my/login/login'
              });
          } else {
            that.setData({
              userId:userInfo.userId
            })
          }
      },
      fail: (err) => {
          if (err.errMsg === 'getStorage:fail data not found') {
              // 数据未找到，当作未登录处理，使用 wx.redirectTo 跳转到登录页面
              console.log("数据未找到");
              wx.showToast({
                title: '还没有登录',
              })
              wx.redirectTo({
                  url: '/pages/my/login/login'
              });
          } else {
              // 其他错误，给出明确提示
              wx.showToast({
                  title: '获取本地存储信息出错，请稍后重试',
                  icon: 'none'
              });
              console.error('获取本地存储信息失败:', err);
          }
      }
    })
    that.setData({
      questionId:options.questionid
    })

  }
})